// pages/score/index.js
var imageUtil = require('../../utils/util.js');
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userScore1:0,
    userScore2:0,
    userScore3:0,
    userScore4:0,
    httphost: app.data.httphost,
    httpserver: app.data.httpserver
  },
  scoreGoods1: function(event){
    app.globalData.cardType = "精粮";
    console.log(event.currentTarget.dataset.score);
    console.log("*********__________"+event.currentTarget.dataset.scoretype);
    var score = event.currentTarget.dataset.score;
    var scoreType1 = event.currentTarget.dataset.scoretype;
    wx.navigateTo({
      url: '../scoreGoods/index?score='+score+"&scoreType="+scoreType1,
    })
  },
  scoreGoods2: function(event){
    app.globalData.cardType = "蔬菜";
    console.log(event.currentTarget.dataset.score);
    console.log("**********__________"+event.currentTarget.dataset.scoretype);
    var score = event.currentTarget.dataset.score;
    var scoreType2 = event.currentTarget.dataset.scoretype;
    wx.navigateTo({
      url: '../scoreGoods/index?score='+score+"&scoreType="+scoreType2,
    })
  },
  scoreGoods3: function(event){
    app.globalData.cardType = "瓜果";
    console.log("**********__________"+event.currentTarget.dataset.scoretype);
    var score = event.currentTarget.dataset.score;
    var scoreType3 = event.currentTarget.dataset.scoretype;
    wx.navigateTo({
      url: '../scoreGoods/index?score='+score+"&scoreType="+scoreType3,
    })
  },
  scoreGoods4: function(event){
    app.globalData.cardType = "肉类";
    console.log("**********__________"+event.currentTarget.dataset.scoretype);
    var score = event.currentTarget.dataset.score;
    var scoreType4 = event.currentTarget.dataset.scoretype;
    wx.navigateTo({
      url: '../scoreGoods/index?score='+score+"&scoreType="+scoreType4,
    })
  },
  bannerLoad: function (e) {
    var imageSize = imageUtil.imageUtil(e)
    this.setData({
      bannerwidth: imageSize.imageWidth,
      bannerheight: imageSize.imageHeight
    })
  }, 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // 调用API从本地缓存中获取数据
    var session_id = wx.getStorageSync('session_id');
    var header = wx.getStorageSync('header');
    if (session_id == '') {
      wx.showToast({
        title: '您还未登录，请先登录！',
        icon: 'none',
        duration: 2000
      })
      return;
    }
    var that = this; 
    wx.request({
      url: app.data.httpserver + 'userScore/list?bannerType=4',
      header: wx.getStorageSync('header'),
      success:function(resqust){
        var banner = resqust.data.bannerlist
        //组合轮播图片
        for (var i = 0; i < banner.length;i++){
          var app_url = banner[i].app_url

          var attr_value = '';
          if (typeof (app_url) != 'undefined' && app_url.indexOf('/')!=-1){
              banner[i].app_url = app_url.split('/')[0];
              // var attr_name_value = app_url.split('?')[1].split('=');
              var attr_value = app_url.split('/')[1];
          }
          banner[i].attr_value = attr_value;
        }
        that.setData({
          banner: banner,
          cart_count: resqust.data.cart_count,
        })
        var arr = resqust.data.list;
        console.log(arr)
        for (let i = 0; i < arr.length; i++) {
          
            that.setData({
              userScore1:arr[i].score1,
              userScore2:arr[i].score2,
              userScore3:arr[i].score3,
              userScore4:arr[i].score4
            })

        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})